<include file="public@header"/>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="{:url('Classes/index')}">班级列表</a></li>
        <li><a href="{:url('Classes/add')}">添加班级</a></li>
    </ul>
    <form class="well js-ajax-form form-inline margin-top-20 row" method="post" action="{:url('Classes/index')}">
        <label class="col-md-3 col-sm-6  form-group" style="margin-bottom:15px">
            所属校区:
            <select class="form-control" name="school_id">
                <option value='0'>全部</option>
                <notempty name="campus">
                    <volist name="campus" id="vo">
                        <if condition="isset($param.school_id) && $param.school_id == $vo.id">
                            <option value="{$vo.id}" selected>{$vo.name}</option>
                            <else/>
                            <option value="{$vo.id}">{$vo.name}</option>
                        </if>
                    </volist>
                </notempty>
            </select>
        </label>

        <label class="col-md-3 col-sm-6   form-group" style="margin-bottom:15px">
            教室:
            <input type="text" class="form-control" name="classroom_name"
                   value="{$param.classroom_name|default=''}" placeholder="按教室搜索">
        </label>

        <label class="col-md-3 col-sm-6  form-group" style="margin-bottom:15px">
            班级人数:
            <select class="form-control" name="student_status" id="student_status">
                <option value="0">全部</option>
                <if condition="isset($param.student_status) && $param.student_status == 1">
                      <option value="1" selected>满员</option>
                    <else/>
                    <option value="1">满员</option>
                    </if>
                <if condition="isset($param.student_status) && $param.student_status ==2">
                    <option value="2" selected>未满员</option>
                    <else/>
                    <option value="2" >未满员</option>
                </if>
            </select>
        </label>
        <label class="col-md-3 col-sm-6  form-group">
        </label>
        <label class="col-md-3 col-sm-6   form-group" style="margin-bottom:15px">
            授课老师:
            <input type="text" class="form-control" name="teacher_id"
                   value="{$param.teacher_id|default=''}" placeholder="按授课老师搜索">
        </label>



        <label class="col-md-3 col-sm-6   form-group">
            班级:
            <input type="text" class="form-control" name="name"
                   value="{$param.name|default=''}" placeholder="按班级搜索">

        </label>
        <label class="col-md-3 col-sm-6   form-group">
            进度:
            <input type="text" class="form-control" name="schedule"
                   value="{$param.schedule|default=''}" placeholder="按班级搜索">

        </label>
        <label class="col-md-3 col-sm-6  form-group">
            开课状态:
            <select class="form-control" name="class_status" id="start_lesson_status">
                <option value="0">全部</option>
                <option value="1" {$a|default="0"}>未开课</option>
                <option value="2" {$b|default="0"}>进行中</option>
                <option value="3" {$c|default="0"}>已结课</option>
            </select>
        </label>
        <label for="开课时间" class="col-md-6 col-xs-12 form-group">
            开课时间:
            <input class="form-control" type="text" name="homework_starttime" id="homework_starttime" style="" value="{:input('request.homework_starttime')}"
                   placeholder="年/月/日">
            -
            <input class="form-control" type="text" name="homework_endtime" id="homework_endtime" style="" value="{:input('request.homework_endtime')}"
                   placeholder="年/月/日">
        </label>

        <label class="col-md-3 col-sm-6   form-group">
            <input type="submit"  class="btn btn-primary" value="搜索"/>
            <a class="btn btn-danger" href="{:url('Classes/index')}">清空</a>
        </label>
    </form>
    <form class="js-ajax-form" action="" method="post" >
        <div class="table-actions">
            <button class="btn btn-danger btn-sm 6 js-ajax-submit" type="submit"
                    data-action="{:url('Classes/delete')}" data-subcheck="true" data-msg="您确定删除吗？">
                批量删除
            </button>
        </div>
        <table class="table table-hover table-bordered table-list">
            <thead>
            <tr>
                <th width="15">
                    <label>
                        <input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
                    </label>
                </th>
                <!--<th width="15">-->
                    <!--<label>-->
                        <!--<input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">-->
                    <!--</label>-->
                <!--</th>-->
                <!--
                <notempty name="category">
                    <th width="50">{:lang('SORT')}</th>
                </notempty>
                -->
                <th width="50">编号</th>
                <th width="100">班级</th>
                <th width="90">所属校区</th>
                <th width="50">教室</th>
                <th width="60">授课老师</th>

                <th width="120">课程</th>
                <th width="70">课程进度</th>
                <th width="50">人数</th>
                <th width="70">开课时间</th>
                <th width="150">操作</th>
            </tr>
            </thead>
            <foreach name="class" item="vo">
                <tr id="data_tr">
                    <td>
                        <input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]"
                               value="{$vo.id}" title="ID:{$vo.id}">
                    </td>
                    <td>{$vo.id}</td>
                    <td class="class_name">{$vo.name}</td>
                    <td>{$vo.campus_name}</td>
                    <td>{$vo.classroom_name}</td>
                    <td>
                        <if condition="empty($vo.user_login)">
                                待定
                            <else />
                            {$vo.user_login}
                           </if>
                    </td>
                    <td>{$vo.course_name}</td>
                    <td>
                        <if condition="$vo.class_status eq 0">
                            <span class="label label-warning">未开课</span>
                            <elseif condition="$vo.class_status eq 2"/>
                            <span class="label label-danger">已结课</span>
                        <else/>
                            <span class="label label-success">{$vo.progress}/{$vo.course_hour}</span>
                        </if>
                    </td>
                    <td>
                        <span title="现有学生数量">{$vo.current_num}/</span>
                        <span title="可报名总人数">{$vo.total_num}</span>
                    </td>
                    <td>
                        {:date('Y-m-d ',$vo.start_lesson_time)}
                    </td>
                    <td>
                        <a href="{:url('Classes/edit',array('id'=>$vo['id']))}">{:lang('EDIT')}</a> |

                        <a href="{:url('Classes/view',array('id'=>$vo['id']))}">学员</a> |
                        <if condition="$vo.is_and_class==0">
                            <a  data-id="{$vo.id}" class="combine_class" style="cursor: pointer;">并班</a> |
                            <else/>
                            <a  data-id="{$vo.id}" class="combine_class_yi">已并班</a> |
                        </if>
                        <a href="{:url('Classes/delete',array('id'=>$vo['id']))}" class="js-ajax-delete">{:lang('DELETE')}</a>
                    </td>
                </tr>
            </foreach>
        </table>
        <div class="pagination">{$page|default=''}</div>
    </form>
    <div id="and_class" style="display:none;padding:20px 30px;">
        <form action="{:url('Classes/addClassPost')}" class="js-ajax-form margin-top-20" method="post">
            <table class="table table-hover table-bordered table-list">
                <thead>
                    <tr>
                        <th>可并去的班级</th>
                    </tr>
                </thead>
                <tbody id="and_tbody">
                    <td>
                        <input type="submit" id="subimt" style="display:none;" class="btn btn-primary ">
                    </td>
                </tbody>
            </table>
        </form>

    </div>
</div>
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
<script src="__STATIC__/js/layer/layer.js"></script>
<script>
    $('[name="homework_starttime"]').datepicker();
    $('[name="homework_endtime"]').datepicker();

    // <!--并班的函数-->
 /*
$('body').on('click','.combine_class',function() {
        var selectedCategoriesId = $(this).attr('data-id');
       openIframeLayer("{:url('classes/Classes/andclass')}?ids=" + selectedCategoriesId, '', {
           area: ['700px', '400px'],
          //  btn: ['确定','取消'],
           title:'并班操作',
           shade:0.3,
           shadeClose:false,
           cancel: function (index, layero) {
             layer.close(index); //如果设定了yes回调，需进行手工关闭
             location.reload();//js刷新页面
           }

        });
    })

*/
 $('body').on('click','.combine_class',function() {
     var old_class_id = $(this).attr('data-id');
     class_name=$(this).parents('tr#data_tr').find('td.class_name').html();
     $.ajax({
         "url":"{:url('Classes/andclass')}" ,
         "data":{
           'ids':old_class_id
         },
         'success':function(data)
         {
            data=jQuery.parseJSON(data);
             //清空dom
             $("#and_tbody").empty();
             if(data.length==0)
             {
                 $("<tr class=and_tr><td>此校区没有可以并班的班级</td></tr>").appendTo("#and_tbody");

             }else{
                 for(var i in data)
                 {
                     $("<tr class='and_tr'><td><input type='checkbox' value='"+data[i].id+"' name='and_class'/>"+data[i].name+"</td></tr>").appendTo("#and_tbody");

                 }
             }

             layer.open
             ({
                 type: 1,
                 btn: ['并班'],
                 title: '并班操作',
                 area: ['300px', '300px'],
                 content: $('#and_class'),
                 yes: function (index,layero) {
                     $original_class_id = old_class_id;
                     $and_class = [];
                     //获取所有的checkbox
                     obj = document.getElementsByName("and_class");
                     for (k in obj) {
                         if (obj[k].checked) {
                             txt = obj[k].value;
                             $and_class.push(txt);
                         }
                     }
                     $.ajax({
                         "url": "{:url('Classes/addClassPost')}",
                         "data": {
                             "original_class_id": $original_class_id,
                             "and_class": $and_class,
                         },
                         'type':'post',
                         "beforeSend": function () {
                             if ($and_class.length == 0) {
                                 layer.msg('请选择班级');
                                 return false;
                             }
                         },
                         'success': function (data) {

                             if(data==1)
                             {
                                 layer.msg('有学生在班级没有选座', {icon: 5, time: 1500}, function () {
                                     location.reload();
                                 });
                             }
                             if(data==2)
                             {
                                 layer.msg('此班级没有学生', {icon: 5, time: 1500}, function () {
                                     location.reload();
                                 });
                             }
                             if(data==3)
                             {
                                 layer.msg('并班成功', {icon: 6, time: 1500}, function () {
                                     location.reload();
                                 });
                             }
                             if(data==4)
                             {
                                 layer.msg('并班失败', {icon: 5, time: 1500}, function () {
                                     location.reload();
                                 });
                             }
                         },
                         'error': function () {
                             layer.msg('并班失败', {icon: 5, time: 1500}, function () {
                                 location.reload();
                             });
                         }

                     })
                 }
                  })
         },
         'error':function()
         {
             layer.msg('并班失败', {icon:5,time:1500},function () {location.reload();});
         }
     })




 })
</script>
</body>
</html>
